<?php

namespace app\admin\model\official;

use think\Model;
use traits\model\SoftDelete;

class OfficialCategory extends Model
{

    use SoftDelete;


    // 表名
    protected $name = 'official_category';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text',
        'is_nav_show_text',
        'is_flooter_nav_show_text',
        'language_text'
    ];


    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (!$row['weigh']) {
                $pk = $row->getPk();
                $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
            }
        });
    }


    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }

    public function getIsNavShowList()
    {
        return ['0' => __('Is_nav_show 0'), '1' => __('Is_nav_show 1')];
    }

    public function getIsFlooterNavShowList()
    {
        return ['0' => __('Is_flooter_nav_show 0'), '1' => __('Is_flooter_nav_show 1')];
    }

    public function getLanguageList()
    {
        return ['1' => __('Language 1'), '2' => __('Language 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsNavShowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_nav_show']) ? $data['is_nav_show'] : '');
        $list = $this->getIsNavShowList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsFlooterNavShowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_flooter_nav_show']) ? $data['is_flooter_nav_show'] : '');
        $list = $this->getIsFlooterNavShowList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLanguageTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['language']) ? $data['language'] : '');
        $list = $this->getLanguageList();
        return isset($list[$value]) ? $list[$value] : '';
    }


}
